<template>
  <!-- 复制处方 -->
  <el-dialog
    :title="patientInfo.name + '的历史处方'"
    :visible="value"
    width="1000px"
    custom-class="dialog-box"
    @close="onClose"
    @open="onOpen"
    :close-on-click-modal="false"
    :append-to-body="true"
  >
    <table class="table-box">
      <thead>
        <tr>
          <th>接诊时间</th>
          <th>接诊类型</th>
          <th>接诊医生</th>
          <th>诊断结果</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <template v-for="item in tableList">
          <tr :key="item.cureId+ item.prescriptionId+'10021'" @click="onclickShow(item)">
            <td>{{ item.treatmentDate }}</td>
            <td>{{ item.diagnosisType }}</td>
            <td>{{ item.doctorName }}</td>
            <td>{{ item.firstVisitInfo }}</td>
            <td>
              <el-link @click.stop="onCopyCF(item)" :underline="false">
                <i class="iconfont iconfuzhi vertical-middle"></i>
                <span class="vertical-middle">选择处方</span>
              </el-link>
            </td>
          </tr>
          <tr
            :key="item.cureId + item.prescriptionId"
            v-if="
              item.curePrescriptionInfoResponses &&
                item.curePrescriptionInfoResponses.length > 0
            "
            style="background-color: white !important; height:0;"
          >
            <td colspan="5" style="padding:0;">
              <div
                v-if="prescriptionType == 1"
                v-show="item.curePrescriptionInfoResponses[0].show"
                style="padding:10px;"
              >
                <h4 style="margin:0;">西/成药处方：</h4>
                <div class="form-box">
                  <div class="form-item">
                    <template
                      v-for="(item, index) in item
                        .curePrescriptionInfoResponses[0]
                        .curePrescriptionDrugInfos"
                    >
                      <table :key="item.id" width="100%" border="0">
                        <tr style="background-color: white !important;">
                          <td>{{ index + 1 }}：{{ item.drugName }}</td>
                          <td width="100">
                            {{ item.useTotal
                            }}{{ item.totalUnit | changeAssist(unitEnum) }}
                          </td>
                          <td width="100">{{ item.useDay }}天</td>
                        </tr>
                      </table>

                      <div :key="item.id+item.drugId" style="padding:0 20px;">
                        用法：{{ item.use | changeAssist(useEnum) }}:{{
                        item.frequency | changeAssist(frequencyEnum)
                        }},每次剂量{{ item.oneDose
                        }}{{ item.oneDoseUnit | changeAssist(unitEnum) }}
                        <span
                          v-if="item.remark"
                        >（{{ item.remark }}）</span>
                      </div>
                    </template>
                  </div>
                </div>
              </div>
              <div v-else v-show="item.show" style="padding:10px;">
                <div v-for="(item, index) in item.curePrescriptionInfoResponses" :key="index">
                  <h4 style="margin:0;">中药处方{{ index > 0 ? index : "" }}：</h4>
                  <br />
                  <div class="form-box">
                    <div class="form-item">
                      <div>
                        <span>每副：</span>
                        <span
                          v-for="(item2,
                          index2) in item.curePrescriptionDrugInfos"
                          :key="index2"
                          style="margin-right:10px;"
                        >
                          {{ item2.drugName }}
                          {{
                          item2.oneDose *
                          item.curePrescriptionUseInfo.totalDose
                          }}{{
                          item2.oneDoseUnit | changeAssist(unitEnum)
                          }}
                        </span>
                      </div>
                      <div style="padding:0 20px;">
                        共{{ item.curePrescriptionUseInfo.totalDose }}副，{{
                        item.curePrescriptionUseInfo.frequency
                        | changeAssist(frequencyEnum)
                        }}，共{{ item.curePrescriptionUseInfo.day }}天
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </td>
          </tr>
        </template>
      </tbody>
    </table>
    <br />
    <div v-if="tableList.length == 0" style="color:#999;padding:10px 0;text-align:center;">
      <i class="iconfont iconwushuju" style="font-size:40px;"></i>
      <div>暂无数据</div>
    </div>
    <br />
    <!-- <pager v-model="pager" @change-pagenum="getData"></pager> -->
  </el-dialog>
</template>
<script>
export default {
  props: ["value", "patientId", "prescriptionType",'cureId'],
  computed: {
    patientInfo() {
      return this.$store.state.doctorMZ.patientInfo;
    },
    //剂量单位
    unitEnum() {
      return this.$store.state.doctorMZ.enum.doseUnitEnum;
    },
    //用法
    useEnum() {
      return this.$store.state.doctorMZ.enum.useEnum;
    },
    //频次
    frequencyEnum() {
      return this.$store.state.doctorMZ.enum.frequencyEnum;
    },
  },
  components: {},
  data() {
    return {
      pager: { pageSize: 20, pageNum: 1, total: 0 },
      tableList: [],
    };
  },
  mounted() {},
  methods: {
    onclickShow(obj) {
      let th = this;
      if (th.prescriptionType == 1) {
        let data = obj.curePrescriptionInfoResponses[0];
        //西药
        th.$set(data, "show", !data.show);
      } else {
        th.$set(obj, "show", !obj.show);
      }
    },
    getData() {
      let j = {
        patientId: this.patientId,
        prescriptionType: this.prescriptionType,
        cureId:this.cureId
      };
      this.showLoading();
      this.$api.prescriptionHistorylist(j).then((res) => {
        if (res.executed) {
          this.tableList = res.data;
          this.showLoading(false);
        }
      });
    },
    //复制处方
    onCopyCF(obj) {
      this.$emit("copySuccess", obj);
      this.onClose();
    },
    onOpen() {
      let th = this;
      th.$nextTick(function () {
        th.getData();
      });
    },
    onClose() {
      let th = this;
      th.tableList = [];
      th.$emit("input", false);
    },
  },
};
</script>
